<template>
    <!-- 添加或修改检验工序对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="工序名称" prop="name">
                                <el-input v-model="form.name" placeholder="请输入工序名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="工序文件">
                                <file-upload v-model="form.file"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="工序图纸" prop="photo">
                                <el-input v-model="form.photo" type="textarea" placeholder="请输入内容"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工序编码" prop="code">
                                <el-input v-model="form.code" placeholder="请输入工序编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="所属工艺" prop="haveGongyi">
                                <el-input v-model="form.haveGongyi" placeholder="请输入所属工艺"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="图纸号" prop="shuoming">
                            <el-input v-model="form.shuoming" placeholder="请输入图纸号"/>
                          </el-form-item>
                        </el-col>
                        <!--<el-col :span="12">
                            <el-form-item label="准备时间" prop="readyDate">
                                <el-date-picker clearable
                                                v-model="form.readyDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择准备时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产时间" prop="prodDate">
                                <el-date-picker clearable
                                                v-model="form.prodDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择生产时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产结束时间" prop="endDate">
                                <el-date-picker clearable
                                                v-model="form.endDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择生产结束时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="质检时间" prop="zhijianDate">
                                <el-date-picker clearable
                                                v-model="form.zhijianDate"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择质检时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>-->
                        <el-col :span="12">
                            <el-form-item label="工时价格" prop="money">
                                <el-input v-model="form.money" placeholder="请输入工时价格"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="设备" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入设备"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "FactoryGongxuForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/factoryGongxu/factoryGongxu/',
                    add:'/factoryGongxu/factoryGongxu/add',
                    edit:'/factoryGongxu/factoryGongxu/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            delFlag: null,
            name: null,
            shuoming: null,
            file: null,
            photo: null,
        status: "0",
            code: null,
            haveGongyi: null,
            isZhijian: null,
            readyDate: null,
            prodDate: null,
            endDate: null,
            zhijianDate: null,
            money: null,
            remark: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加检验工序";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改检验工序";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
